import React, { useState } from "react";
import { Select } from "antd";
import Notfound from "../notFound/not-found";
const { Option } = Select

const XxSelect = (props) => {
    const {
        url,//搜索地址，如果需要搜索就会用上
        defaultValue,//默认显示的value
        notFoundContent = "无可选项",//下拉 列表为空时显示的内容
        placeholder,
        showSearch = true,//配置是否可搜索 默认否
        size,//尺寸
        onInputKeyDown,//按钮按下时的回调：通常用来 按下去后 去搜索数据
        allowClear = true,//支持清除？默认否
        fieldNames = null,
    } = props
    const [data, setData] = useState(props.options || []);//下拉列表框
    const [value, setValue] = useState();//输入框的值
    const [loading, setLoading] = useState(false);//是否在加载中



    const handleChange = (newValue) => {
        setValue(newValue);
    };

  
    return (

        <>
            <Select
                defaultValue={defaultValue}
                notFoundContent={<Notfound />}
                placeholder={placeholder}
                showSearch={showSearch}
                value={value}
                size={size}
                allowClear={allowClear} //支持清除
                // onFocus={() => handleSearch("")}  //鼠标按下去的时候就搜索
                defaultActiveFirstOption={false}
                filterOption={false}
                // onSearch={handleSearch}
                onChange={handleChange}
                loading={loading}
                {...props}
                fieldNames={fieldNames}
            >
                {
                    data.map((item, index) => {
                        return (
                            <Option key={index} value={item.value}>{item.label}</Option>
                        )
                    })
                }

            </Select>
        </>



    )
}

export default XxSelect;